package com.yonyou.chuan.servlet;

import cn.hutool.json.JSONUtil;
import com.yonyou.chuan.log.LoggerUtil;
import com.yonyou.chuan.model.vo.YhtFlowVO;
import com.yonyou.chuan.service.YhtPubService;
import nc.bs.framework.adaptor.IHttpServletAdaptor;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.server.ISecurityTokenCallback;
import nccloud.putitf.riart.billtype.IDefaultQueryRelatedAppInfoService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class YhtPubServlet implements IHttpServletAdaptor {

    @Override
    public void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
            String flowid = request.getParameter("flowid");
            LoggerUtil.printLogger("【友互通待办详情查询】,流程主键:{}",flowid);
            YhtFlowVO flowVO = NCLocator.getInstance().lookup(YhtPubService.class).queryWorkFlow(flowid);
            String billType = flowVO.getBillType();
            //查询默认模版 包含移动端  以及页面地址
            Map<String, Object> info = NCLocator.getInstance().lookup(IDefaultQueryRelatedAppInfoService.class).getRelatedAppInfoMap(billType, 3);
            response.setContentType("application/json;  charset=UTF-8");
            Map<String, Object> result = new HashMap<>();
            result.put("info",info); //ss
            result.put("flowVO",flowVO);
            response.getWriter().write(JSONUtil.toJsonStr(result));
        } catch (Exception e) {
            LoggerUtil.printLogger("【友互通待办详情查询】,报错信息:{}",e.getMessage());
            response.setContentType("application/json;  charset=UTF-8");
            response.getWriter().write("报错:" + e.getMessage());
        }finally {
            response.getWriter().close();
        }
    }

}
